package com.etc.service;

import com.etc.dao.OrderDao;
import com.etc.dao.UserDao;
import com.etc.entity.Order;
import com.etc.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.ArrayList;
import java.util.List;

public class OrderService implements OrderDao {


    private SqlSessionFactory sqlSessionFactory;

    public OrderService(SqlSessionFactory sqlSessionFactory){
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public List<Order> findOrdersWithUserResultMap() {
        // 数据库会话实例
        SqlSession sqlSession = null;
        try {
            // 创建数据库会话实例sqlSession
            sqlSession = sqlSessionFactory.openSession();
            // 查询单个记录，根据用户id查询用户信息
            List<Order> user = sqlSession.selectList("findOrdersWithUserResultMap");
            return user;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            if (sqlSession != null) {
                sqlSession.close();
            }
        }
    }
}
